<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加规则</title>
<link href="../../../css/bg/styles/layout.css" th:href="@{/css/bg/styles/layout.css}" rel="stylesheet" type="text/css" />
<link href="../../../css/bg/styles/wysiwyg.css" th:href="@{/css/bg/styles/wysiwyg.css}" rel="stylesheet" type="text/css" />
<!-- Theme Start -->
<link href="../../../css/bg/themes/blue/styles.css" th:href="@{/css/bg/themes/blue/styles.css}" rel="stylesheet" type="text/css" />
<!-- Theme End -->
</head>
<body id="homepage">
	<div id="header">
    	<a href="" title=""><img src="../../../css/bg/img/cp_logo.png" th:src="@{/css/bg/img/cp_logo.png}" alt="Control Panel" class="logo" /></a>
    	<div id="searcharea">
            
        </div>
    </div>
        
    <!-- Top Breadcrumb Start -->
    <div id="breadcrumb">
    	<ul>	
        	<li><img src="../../../css/bg/img/icons/icon_breadcrumb.png" th:src="@{/css/bg/img/icons/icon_breadcrumb.png}" alt="当前位置" /></li>
        	<li><strong>当前位置:</strong></li>
            <li><a href="#" title="">号码规则</a></li>
            <li>/</li>
            <li class="current">添加规则</li>
        </ul>
    </div>
    <!-- Top Breadcrumb End -->
     
    <!-- Right Side/Main Content Start -->
    <div id="rightside">
        <div class="status success" th:if="${success == true}">
        	<p class="closestatus"><a href="" title="Close">x</a></p>
        	<p><img src="../../../css/bg/img/icons/icon_success.png" th:src="@{/css/bg/img/icons/icon_success.png}" alt="Success" /><span>配置保存成功!</span></p>
        </div>
        <div class="status error" th:if="${success == false}">
        	<p class="closestatus"><a href="" title="Close">x</a></p>
        	<p><img src="../../../css/bg/img/icons/icon_error.png" th:src="@{/css/bg/img/icons/icon_error.png}" alt="Error" /><span>配置保存失败!</span></p>
        </div>
         <div class="contentcontainer">
            <div class="headings altheading">
                <h2>添加号码规则</h2>
            </div>
            <div class="contentbox">
	            
            		<form action="" th:action="@{/rule/add}" method="post" enctype="application/x-www-form-urlencoded">
            			<p>
	                        <label for="textfield"><strong>号码规则:</strong></label>
	                        <input type="text" class="inputbox" name="rule" id="rule" style="width:80%;" />
	                        <img src="../../../css/bg/img/icons/icon_missing.png" th:src="@{/css/bg/img/icons/icon_missing.png}" alt="Approve" id="rule_error_img" />
	                        <img src="../../../css/bg/img/icons/icon_approve.png" th:src="@{/css/bg/img/icons/icon_approve.png}" alt="Approve" id="rule_correct_img" />
	                        <br />
	                        <span class="smltxt" id="rule_info"></span>
	                    </p>
	                    
	            		<p>
	                        <label for="textfield"><strong>最低消费:</strong></label>
	                        <input type="text" class="inputbox" name="price" id="price" />元/年
	                        <img src="../../../css/bg/img/icons/icon_missing.png" th:src="@{/css/bg/img/icons/icon_missing.png}" alt="Approve" id="price_error_img" />
	                        <img src="../../../css/bg/img/icons/icon_approve.png" th:src="@{/css/bg/img/icons/icon_approve.png}" alt="Approve" id="price_correct_img" />
	                        <br />
	                        <span class="smltxt" id="price_info"></span>
	                    </p>
	                    
	                    <p>
	                        <label for="textfield"><strong>别名:</strong></label>
	                        <input type="text" class="inputbox" name="alias" id="alias" style="width:80%;" /><br />
	                        <span class="smltxt"></span>
	                    </p>
	            		
	            		<p>
		            		<label for="textfield"><strong>备注:</strong></label>
		            		<textarea id="comment" name="comment" style="width:80%;height:120px;" class="inputbox"></textarea>
	            		</p>
	            		<br />
	            		<input type="button" class="btn" value="保存" id="button_save" />
            		</form>
    			</div>
            </div>
            	
        </div>
        
         
        <!-- Content Box End -->
        <div id="footer">
        	
        </div> 
          
    <!-- Right Side/Main Content End -->
    
        <!-- Left Dark Bar Start -->
    <div id="leftside">
    	<div class="user">
            <p>&nbsp;</p>
        </div>
        
        <ul id="nav" th:include="bg/lefttree :: nav_tree">
        	<li>
        		<a class="expanded heading">配置</a>
                <ul class="navigation">
                    <li><a href="config.html" th:href="@{/config}" title="">系统参数配置</a></li>
                </ul>
            </li>
            <li>
            	<a class="expanded heading">号码信息查询</a>
                <ul class="navigation">
                    <li><a href="querysingle.html" th:href="@{/query/single}" title="">单条查询</a></li>
                    <li><a href="querymulti.html" th:href="@{/query/multi}" title="">多条查询</a></li>
                </ul>
            </li>
            <li>
            	<a class="expanded heading">号码规则</a>
                <ul class="navigation">
                    <li><a href="rules.html" th:href="@{/query/single}" title="">规则列表</a></li>
                    <li><a href="addRule.html" th:href="@{/query/single}" title="">添加规则</a></li>
                    <li><a href="matchRule.html" th:href="@{/rule/match}" title="">匹配规则</a></li>
                </ul>
            </li>         
        </ul>
    </div>
    <!-- Left Dark Bar End --> 
    <!-- 
    <script type="text/javascript" src="http://dwpe.googlecode.com/svn/trunk/_shared/EnhanceJS/enhance.js"></script>	
    <script type='text/javascript' src='http://dwpe.googlecode.com/svn/trunk/charting/js/excanvas.js'></script>
	<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'></script>
    <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js'></script>--> 

    <script type='text/javascript' src='../../../js/libs/jquery-1.7.1.min.js' th:src="@{/js/libs/jquery-1.7.1.min.js}"></script>
    <script type='text/javascript' src='../../../js/libs/jquery-ui-1.8.5.custom.min.js' th:src="@{/js/libs/jquery-ui-1.8.5.custom.min.js}"></script>
    <script type='text/javascript' src='../../../js/bg/jquery.bpopup-0.6.0.min.js' th:src="@{/js/bg/jquery.bpopup-0.6.0.min.js}"></script>
	<script type='text/javascript' src='../../../js/bg/jquery.wysiwyg.js' th:src="@{/js/bg/jquery.wysiwyg.js}"></script>
    <script type='text/javascript' src='../../../js/bg/visualize.jQuery.js' th:src="@{/js/bg/visualize.jQuery.js}"></script>
    <script type="text/javascript" src='../../../js/bg/functions.js' th:src="@{/js/bg/functions.js}"></script>
    <!-- script type="text/javascript" src='../../../js/bg/modifyNumRule.js' th:src="@{/js/bg/modifyNumRule.js}"></script-->
    <!--[if IE 6]>
    <script type='text/javascript' src='scripts/png_fix.js'></script>
    <script type='text/javascript'>
      DD_belatedPNG.fix('img, .notifycount, .selected');
    </script>
    <![endif]--> 
    <script type="text/javascript" th:inline="javascript">
    	setCurrentNav(2);
    	
    	$('form').find('img').css('display','none');
    	
    	var edit_url = /*[[@{/rule}]]*/'';
    	
    	$('#rule').blur(function(){
    		var rule = $(this).val().toUpperCase();
    		$(this).val(rule);
    		var info_field = $('#rule_info');
    		
    		$.ajax({
				url:edit_url+'/'+rule,
				type:'POST',
				success:function(data, textStatus, jqXHR){
					var resultObj = $.parseJSON(data);
					console.log(resultObj);
					if(resultObj.success == 'true'){
						if(resultObj.result == 'false'){
							$(info_field).text('');
							$('#rule').addClass('correctbox').removeClass('errorbox');
							$('#rule_correct_img').show();
							$('#rule_error_img').hide();
						}else{
							$(info_field).text('规则已存在');
							$('#rule').addClass('errorbox').removeClass('correctbox');
							$('#rule_error_img').show();
							$('#rule_correct_img').hide();
						}
					}else{
						$(info_field).text('规则查询失败');
					}
				},
				error:function(jqXHR, textStatus, errorThrown){
				}
			});
    	});
    	
    	var checkPriceField = function(){
    		var price = $('#price').val();
    		var info_field = $('#price_info');
    		if($.isNumeric(price)){
    			$(info_field).text('');
    			$('#price').addClass('correctbox').removeClass('errorbox');
				$('#price_correct_img').show();
				$('#price_error_img').hide();
    		}else{
    			$(info_field).text('价格输入不正确，请输入数字');
				$('#price').addClass('errorbox').removeClass('correctbox');
				$('#price_error_img').show();
				$('#price_correct_img').hide();
    		}
    	}
    	
    	$('#price').blur(checkPriceField);
    	
    	$('#button_save').click(function(){
    		checkPriceField();
    		
    		var status = true;
    		
    		$('input').each(function(){
    			if($(this).hasClass('errorbox')){
    				status = false;
    			}
    		});
    		
    		if(status){
    			$('form').submit();
    		}
    	});
    	
    </script>
</body>
</html>
